package it.xiuxian.personcenter.presenter

import com.lzy.okgo.OkGo
import it.xiuxian.lib.base.*
import it.xiuxian.lib.http.CallBackOption
import it.xiuxian.lib.http.HttpConfig
import it.xiuxian.personcenter.bean.ImageBean
import it.xiuxian.lib.bean.NewPersonBean
import it.xiuxian.personcenter.bean.ShiMIngBean
import it.xiuxian.personcenter.fragment.PersonCenterFragment
import java.io.File

class PersonCenterFragmentPresenter: BasePresenter<PersonCenterFragment>() {
    fun getHomePage(){
        OkGo.post<BaseBean<NewPersonBean>>(HttpConfig.BASE_URL+"/appuser/info")
            .execute(object : CallBackOption<BaseBean<NewPersonBean>>() {}.loadBind(mView as PersonCenterFragment).execute(
                object :ILoadBind<BaseBean<NewPersonBean>>{
                    override fun excute(bean: BaseBean<NewPersonBean>) {
                         if(bean.code==0){
                            (mView as PersonCenterFragment).setUI(bean.data)
                        }
                    }
                }
            ))
    }
    fun getShiming(){
        OkGo.post<BaseBean<ShiMIngBean>>(HttpConfig.BASE_URL+"/appshiming/get")
            .execute(object : CallBackOption<BaseBean<ShiMIngBean>>() {}.loadBind(mView as PersonCenterFragment).execute(
                object :ILoadBind<BaseBean<ShiMIngBean>>{
                    override fun excute(bean: BaseBean<ShiMIngBean>) {
                        if(bean.code==0){
                            (mView as PersonCenterFragment).setShiMing(bean.data)
                        }
                    }
                }
            ))
    }
    fun onload(file: File){
       OkGo.post<BaseBean<ImageBean>>(HttpConfig.BASE_URL + "/appuser/updatetouxiang")
            .isMultipart(false)
            .params( "file", file)
            .execute(object : CallBackOption<BaseBean<ImageBean>>() {}.loadBind(mView as PersonCenterFragment).execute(
                object :ILoadBind<BaseBean<ImageBean>>{
                    override fun excute(bean: BaseBean<ImageBean>) {
                        if(bean.code==0){
                            (mView as PersonCenterFragment).updata(bean.data)
                        }
                    }
                }
            ))
    }

}